<% layout('/layout/default.html', {title: '角色管理', libs: ['dataGrid']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header">
			<div class="box-title">
				<i class="fa icon-people"></i> 角色授权用户（${role.name}-${role.roleType}）
			</div>
			<div class="box-tools pull-right">
				<a href="#" class="btn btn-default" id="btnAddUser" title="添加用户"><i class="fa fa-plus"></i> 添加用户</a>
				<a href="#" class="btn btn-default" id="btnDelUser" title="删除用户"><i class="fa fa-remove"></i> 批量取消</a>
				<a href="javascript:" class="btn btn-default" onclick="window.parent.closeCurrentTabPage();"><i class="fa fa-reply-all"></i> 关 闭</a>
			</div>
		</div>
		<div class="box-body">
			<form id="searchForm" action="${ctx}/sys/user/listData" method="post" class="form-inline " >
				<input name="role.id" type="hidden" value="${role.id}" />
				<div class="form-group">
					<label class="control-label">账号：</label>
					<div class="control-inline">
						<input name="loginName" maxlength="100" class="form-control width-90"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">昵称：</label>
					<div class="control-inline">
						<input name="name" maxlength="100" class="form-control width-90"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">邮箱：</label>
					<div class="control-inline">
						<input name="email" maxlength="300" class="form-control width-90"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">手机：</label>
					<div class="control-inline">
						<input name="mobile" maxlength="100" class="form-control width-90"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">电话：</label>
					<div class="control-inline">
						<input name="phone" maxlength="100" class="form-control width-90"/>
					</div>
				</div>
				<div class="form-group">
					<button type="submit" class="btn btn-primary btn-sm">查询</button>
					<button type="reset" class="btn btn-default btn-sm">重置</button>
				</div>
			</form>			
			<table id="dataGrid"></table>
			<div id="dataGridPage"></div>
		</div>
	</div>
</div>
<div class="hide">
<#form:listselect id="userSelect" title="用户选择"
	url="${ctx}/sys/role/usertorole?userType=${role.userType}" allowClear="false" 
	checkbox="true" itemCode="id" itemName="name"/>
</div>
<% } %>
<script>
//初始化DataGrid对象
$('#dataGrid').dataGrid({
	searchForm: $("#searchForm"),
	columnModel: [
		{header:'登录账号', name:'loginName', index:'a.login_name', width:200, align:"center"},
		{header:'用户昵称', name:'name', index:'a.name', width:200, align:"center"},
		{header:'电子邮箱', name:'email', index:'a.email', width:200, align:"center"},
		{header:'手机号码', name:'mobile', index:'a.mobile', width:200, align:"center"},
		{header:'办公电话', name:'phone', index:'a.phone', width:200, align:"center"},
		{header:'更新时间', name:'updateDate', index:'a.update_date', width:200, align:"center"},
		/* {header:'状态', name:'status', index:'a.status', width:100, align:"center", formatter: function(val, obj, row, act){
			return js.transDictLabel(${@DictUtils.getDictListJson('sys_status')}, val, '未知');
		}}, */
		{header:'操作', name:'actions', width:100, sortable:false, title:false, align:"center", formatter: function(val, obj, row, act){
			var actions = [];
			actions.push('<a href="${ctx}/sys/role/outrole?id=${role.id}&userRoleString='+row.id+'" class="btnList" title="取消授权" data-confirm="确认要取消该用户角色吗？"><i class="fa fa-remove"></i></a>&nbsp;');
			return actions.join('');
		}}
	],
	showCheckbox: true,
	// 加载成功后执行事件
	ajaxSuccess: function(data){
		
	}
});
$('#btnDelUser').click(function(){
	var userCodes = $('#dataGrid').dataGrid('getSelectRows');
	if (userCodes != null && userCodes.length > 0){
		js.confirm('确认要取消列表中权重的用户角色权限吗？', function(){
			js.ajaxRequest('${ctx}/sys/role/outrole', {
				id: '${role.id}',
				userRoleString: userCodes.join(',')
			}, function(data){
				js.showMessage(data.message);
				page();
			});
		});
	}else{
		js.showMessage('请在列表选中要取消角色的用户');
	}
	return false;
});
$('#btnAddUser').click(function(){
	$('#userSelectName').click();
});
function listselectCallback(id, action, index, layero){
	if (id == 'userSelect' && action == 'ok'){
		if ($('#userSelectCode').val() != ''){
			js.ajaxRequest('${ctx}/sys/role/assignrole', {
				id: '${role.id}',
				userRoleString: $('#userSelectCode').val()
			}, function(data){
				js.showMessage(data.message);
				page();
			});
		}else{
			js.showMessage('没有选择要授权的用户');
		}
	}
}
</script>
